home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / dev / c / libiconv_src.lha / tools / cjk_variants.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-07  |  1.9 KB  |  91 lines

  1. /*
  2.  * Generates Unicode variants table from Koichi Yasuoka's UniVariants file.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. #define ENTRIES  8176  /* number of lines in UniVariants file */
  9. #define MAX_PER_ENTRY  10  /* max number of entries per line in file */
  10.  
  11. int main (int argc, char *argv[])
  12. {
  13.   int variants[MAX_PER_ENTRY*ENTRIES];
  14.   int uni2index[0x10000];
  15.   int index;
  16.  
  17.   if (argc != 1)
  18.     exit(1);
  19.  
  20.   printf("\n");
  21.   printf("/*\n");
  22.   printf(" * CJK variants table\n");
  23.   printf(" */\n");
  24.   printf("\n");
  25.   {
  26.     int c;
  27.     int j;
  28.     for (j = 0; j < 0x10000; j++)
  29.       uni2index[j] = -1;
  30.     index = 0;
  31.     for (;;) {
  32.       c = getc(stdin);
  33.       if (c == EOF)
  34.         break;
  35.       if (c == '#') {
  36.         do { c = getc(stdin); } while (!(c == EOF || c == '\n'));
  37.         continue;
  38.       }
  39.       ungetc(c,stdin);
  40.       if (scanf("%x",&j) != 1)
  41.         exit(1);
  42.       c = getc(stdin);
  43.       if (c != '\t')
  44.         exit(1);
  45.       uni2index[j] = index;
  46.       for (;;) {
  47.         int i;
  48.         if (scanf("%x",&i) != 1)
  49.           exit(1);
  50.         if (!(i >= 0x3000 && i < 0x3000+0x8000))
  51.           exit(1);
  52.         variants[index++] = i-0x3000;
  53.         c = getc(stdin);
  54.         if (c != ' ')
  55.           break;
  56.       }
  57.       variants[index-1] |= 0x8000; /* end of list marker */
  58.       if (c != '\n')
  59.         exit(1);
  60.     }
  61.   }
  62.   printf("static const unsigned short cjk_variants[%d] = {",index);
  63.   {
  64.     int i;
  65.     for (i = 0; i < index; i++) {
  66.       if ((i % 8) == 0)
  67.         printf("\n ");
  68.       printf(" 0x%04x,",variants[i]);
  69.     }
  70.     printf("\n};\n");
  71.   }
  72.   printf("\n");
  73.   printf("static const short cjk_variants_indx[0x5200] = {\n");
  74.   {
  75.     int j;
  76.     for (j = 0x4e00; j < 0xa000; j++) {
  77.       if ((j % 0x100) == 0)
  78.         printf("  /* 0x%04x */\n", j);
  79.       if ((j % 8) == 0)
  80.         printf(" ");
  81.       printf(" %5d,",uni2index[j]);
  82.       if ((j % 8) == 7)
  83.         printf("\n");
  84.     }
  85.     printf("};\n");
  86.   }
  87.   printf("\n");
  88.  
  89.   return 0;
  90. }
  91.